home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / Evatac Software / Preditor 3.0 / Tools / Language Module Builder / LanguageModule.h < prev    next >
Text File  |  1995-11-14  |  5KB  |  216 lines

  1. /************************************************************
  2.  
  3.     LanguageModule.h
  4.     
  5.     Interface file for Preditor language modules
  6.  
  7.     © Copyright Evatac Software  1988-1995
  8.     All rights reserved
  9.  
  10. ************************************************************
  11.  
  12.     Language modules are compose of resources, and code.
  13.     The header file deals with the code in a language module.
  14.     
  15.     The language module code is based on Preditor extensions.
  16.     Language modules main entry point gets called just as
  17.     an extension would -- the only difference being that there
  18.     are 2 additional parameters -- the "what to do" parameter,
  19.     and the 'data' parameter.  Language modules also have
  20.     legitimate access to the "TokenReturn" extension entry point.
  21.  
  22.      Your definition of 'main' should look like this:
  23.      
  24.        void main(
  25.            ExternalCallbackBlock    *callbacks,
  26.            WindowRef                window
  27.            long                    command,
  28.            void                    *data
  29.            );
  30.      
  31.      The 'data' value is defined for the following commands:
  32.      
  33.      kLanguageTemplate        (long) Index of template to insert
  34.      kLanguageElectric        (Char) electric character typed
  35.      
  36. ************************************************************/
  37.  
  38. #ifndef __LANGUAGEMODULE__
  39. #define __LANGUAGEMODULE__
  40.  
  41. #include "PreditorExtension.h"
  42.  
  43.  
  44. /*
  45.  * * * * * * * * * CONSTANTS AND MACRO DEFINITIONS * * * * * * * * * *
  46.  */
  47.  
  48. /*
  49.  * Language commands -- 'command' parameter to language module.
  50.  * These are the built-in/required command -- all language
  51.  * modules must handle these in some fashion.
  52.  */
  53. enum {
  54.     kLanguageParse        = 0,
  55.     kLanguageFunctions,
  56.     kLanguageIncludes,
  57.     kLanguageTemplate,
  58.     kLanguageIndent,
  59.     kLanguageElectric
  60. };
  61.  
  62. #define kTokenStringSize            64
  63. #define kEOL                        13
  64.  
  65. /*
  66.  * * * * * * * * * TYPE AND STRUCTURE DEFINITIONS * * * * * * * * * *
  67.  */
  68.  
  69. /*
  70.  * The 'languageToken' is returned though the "TokenReturn"
  71.  * callback.  The language module call this when determing
  72.  * functions, language-tokens and includes for a source file
  73.  */
  74.  
  75. typedef struct languageToken {
  76.     Int16        type;
  77.     Int16        majorType;
  78.     
  79.     Char        string[kTokenStringSize + 2];
  80.     
  81.     Int32        startLocation;
  82.     Int32        endLocation;
  83.     Int32        commentLocation;
  84. } languageToken;
  85.  
  86. typedef struct languageGlobals {
  87.     Handle                tokenTable;
  88.     Handle                customTokenTable;
  89.     languageToken        token;
  90.     Int32                position;
  91.     Int32                startLastComment;
  92.     short                ungetBuffer[3];
  93.     short                ungetCount;
  94.     Boolean                expired;
  95. } languageGlobals;
  96.  
  97. #if GENERATINGCFM
  98.  
  99. enum {
  100.     LanguageUPPInfo    = kCStackBased
  101.                 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ExternalCallbackBlock *)))
  102.                  | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(WindowRef)))
  103.                  | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long)))
  104.                  | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(void *)))
  105. };
  106.  
  107. #endif
  108.  
  109. /*
  110.  * * * * * * * * * FUNCTION PROTOTYPES * * * * * * * * * *
  111.  */
  112.  
  113. /*
  114.  * Your language module can make calls to the following public
  115.  * entry points, found in the LanguageModuleLib
  116.  */
  117.  
  118. void languageInit(        
  119.     languageGlobals            *info,
  120.     ExternalCallbackBlock    *callbacks,
  121.     long                    options
  122.     );
  123.     
  124. void languageDone(
  125.     languageGlobals            *info,
  126.     ExternalCallbackBlock    *callbacks
  127.     );
  128.     
  129. void languageDefaultHandler(
  130.     languageGlobals            *info,
  131.     ExternalCallbackBlock    *callbacks,
  132.     long                    options,
  133.     void                    *data
  134.     );
  135.     
  136. int languageGetChar(
  137.     languageGlobals            *info,
  138.     ExternalCallbackBlock    *callbacks
  139.     );
  140.  
  141. int languageUngetChar(
  142.     languageGlobals            *info,
  143.     ExternalCallbackBlock    *callbacks
  144.     );
  145.     
  146. int languagePeekChar(
  147.     languageGlobals            *info,
  148.     ExternalCallbackBlock    *callbacks
  149.      );
  150.     
  151. short languageCStringCompare(
  152.     Char   *s1, 
  153.     Char   *s2
  154.     );
  155.  
  156. /*
  157.  * This function does a hash lookup for the given cstring, returning
  158.  * true if it's a reserved token.  This table is only defined
  159.  * for the     kLanguageParse & kLanguageIncludes commands.
  160.  */
  161.  
  162. Boolean languageTableLookup(
  163.     languageGlobals        *info,
  164.     Char                cstring
  165.     );
  166.     
  167. Boolean languageCustomTableLookup(
  168.     languageGlobals        *info,
  169.     Char                cstring
  170.     );
  171.  
  172. Boolean languageHasTable(
  173.     languageGlobals        *info
  174.     );
  175.     
  176. /*
  177.  * These are private --- used by the language builder application
  178.  */
  179.  
  180. Handle stringTableCreate(void);
  181.     
  182. void stringTableDestroy(
  183.     Handle        table
  184.     );
  185.  
  186. void stringTableIntern(
  187.     Handle        table,
  188.     Char        *name
  189.     );
  190.     
  191. void stringTableWriteResource(
  192.     Handle        table,
  193.     short        resourceId
  194.     );
  195.  
  196. Handle stringTableReadResource(
  197.     short            resourceId
  198.     );
  199.     
  200. Boolean stringTableLookup(
  201.     Handle                table,
  202.     Char                *name
  203.     );
  204.  
  205. /*
  206.  * * * * * * * * * PRIVATE MACROS * * * * * * * * * *
  207.  */
  208.  
  209. #define languageUngetChar(g,c)        ((g)->ungetBuffer[(g)->ungetCount++] = (c), \
  210.                                      (g)->position--)
  211. #define languageHasTable(g)            ((g)->tokenTable != nil)
  212. #define languageTableLookup(g,c)        stringTableLookup(g->tokenTable, c)
  213. #define languageCustomTableLookup(g,c)    stringTableLookup(g->customTokenTable, c)
  214.  
  215. #endif
  216.